#pragma once
#include "MemStream.h"
#include "his_stream.h"
#include "RecvMsg.h"
#include "Config.h"
#include <memory>
#include <thread>
#include <boost/asio.hpp>
#include "chip_type.h"
#include "HTBlockQueue.h"


class Client
	:public std::enable_shared_from_this<Client>
{
public:
	Client(boost::asio::io_service& ioservice, SERVICE_CONFIG srv, STOCK_CONFIG stock, int interval, int retry);
	~Client();


	void StartWorker(std::function<void(std::string &&)> fun);
	void do_connect();
	void do_write_buffer();

	void ProccessPackage();
	void do_read_header();
	void do_read_body();

	void do_heartBeat(const boost::system::error_code& error);
	void do_request(const boost::system::error_code& error);

	void PushMQResult(int status, int date, int time, const std::string &data);
	void AsyncSleep(int seconds);
	void PushDisConnect();
	void PushConnect();
private:
	boost::asio::io_service& m_IOservice;
	boost::asio::ip::tcp::socket m_socket;
	boost::asio::deadline_timer m_deadlineTimer;
	boost::asio::deadline_timer m_RequestTimer;
	boost::asio::io_service::strand m_strand;

	std::function<void(std::string &&)> funRet;
	SERVICE_CONFIG m_srvcfg;
	STOCK_CONFIG m_stockcfg;
	int   m_Interval;
	int   m_Retry;
	CHisStream m_sendBuffer;
	CRecvMsg m_msg;

	CMemStream dataWrite;

// 	std::thread m_tProccess;
// 	std::atomic<bool> bExit;
// 	CHTBlockQueue<ChipData> sRecordLst;

};

